package wjh.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import wjh.pojo.Doctor;
import wjh.service.DoctorInfoService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;

@Controller
@RequestMapping("/doctorInfo")
public class DoctorInfo {
    @Autowired
    private DoctorInfoService doctorInfoService;
    @RequestMapping("/parseId")
    public String parseId(@RequestParam("id") Integer id, HttpSession session){
        session.setAttribute("id",id);
        Doctor doctor = doctorInfoService.findDoctorById(id);
        String doctorName = doctor.getName();
        session.setAttribute("doctorName",doctorName);
        return "doctorIndex";
    }
    @RequestMapping("/findDoctorById")
    public String findUserById(@RequestParam("id")String id,Model model){
        Doctor doctor = doctorInfoService.findDoctorById(Integer.parseInt(id));
        model.addAttribute("doctor",doctor);
        return "forward:/jsp/doctorInfo.jsp";
    }
    @RequestMapping("/updateInfo")
    public String updateInfo(Doctor doctor, MultipartFile file, HttpServletRequest request,Model model)throws ParseException {
        doctorInfoService.updateInfo(doctor,file,request);
        int id=doctor.getId();
        model.addAttribute("id",id);
        return "forward:/jsp/doctorIndex.jsp";//redirect:/user/findAll.do
    }
}
